//
//  NMPOServerNavView.swift
//  NMPO
//
//  Created by PowerfullClean on 2023/10/31.
//

import UIKit

class NMPOServerNavView: NMPOServersListNavView {
    override func nmpo_initViews() {
        super.nmpo_initViews()
        addSubview(nmpo_connectButton)
        
        nmpo_connectButton.snp.makeConstraints { make in
            make.centerY.equalTo(nmpo_leftButton.snp.centerY)
            make.right.equalToSuperview().offset(-20)
            make.size.equalTo(CGSize(width: 24, height: 24))
        }
    }
    
    override func nmpo_buttonClick(sender: UIButton) {
        if sender == nmpo_connectButton {
            if NMPOManager.nmpo_manager.nmpo_vpnCurStateType == .nmpo_connected {
                NMPOManager.nmpo_manager.nmpo_vpnStateClickType = .nmpo_disConnect
            }else {
                NMPOManager.nmpo_manager.nmpo_vpnStateClickType = .nmpo_connect
            }
            
            NMPOManager.nmpo_manager.nmpo_connectSmartAction()
            nmpo_viewGetVController?.navigationController?.popToRootViewController(animated: true)
            return
        }
        super.nmpo_buttonClick(sender: sender)
    }
    lazy var nmpo_connectButton: UIButton = {
        let nmpo_connectButton = UIButton()
        nmpo_connectButton.setImage(UIImage(named: "nmpo_nav_connect"), for: .normal)
        nmpo_connectButton.addTarget(self, action: #selector(nmpo_buttonClick(sender:)), for: .touchUpInside)
        return nmpo_connectButton
    }()
}
